//
//  ShouHouViewController.m
//  JiuJiuShangCheng
//
//  Created by jiujiukeji on 2018/7/16.
//  Copyright © 2018年 jiujiukeji. All rights reserved.
//

#import "PingJiaViewController.h"
#import "OrderTableViewCell.h"
#import "ShouHouTableViewCell.h"
#import "UITextView+Extension.h"
#import "MyStarView.h"
#import "TZTestCell.h"
#import "TZImagePickerController.h"
#import "DPPhotoGroupViewController.h"

@interface PingJiaViewController ()<UITableViewDelegate,UITableViewDataSource,TZImagePickerControllerDelegate,UICollectionViewDelegate, UICollectionViewDataSource,DPPhotoGroupViewControllerDelegate,UITextFieldDelegate,UITextViewDelegate>
{
    NSMutableArray *_selectedAssets;
    BOOL _isSelectOriginalPhoto;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) MyStarView *starsView;
@property (nonatomic, strong) NSMutableArray *selectedPhotos;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSString *star;
@property (nonatomic, strong) NSMutableDictionary *infoDic;
@property (nonatomic, strong) NSMutableArray *filePathArray;

@end

@implementation PingJiaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = tableViewBgColor;
    [self loadBaseTitleLable:@"商品评价"];
    self.star = @"5";
    self.infoDic = [NSMutableDictionary dictionary];
    self.filePathArray = [NSMutableArray array];
    
    [self.view addSubview:self.tableView];
}
#pragma mark - tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        OrderTableViewCell *cell = [[OrderTableViewCell alloc] init];
        cell.contentView.backgroundColor = UIColorWhite;
        [cell.goodsImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http:%@",self.goodsDic[@"CartImg"]]]];
        cell.goodsTitleLB.text = self.goodsDic[@"CommodityName"];
        cell.priceLB.text = [NSString stringWithFormat:@"￥%.2f",[self.goodsDic[@"CommodityXPrice"] floatValue]];
        cell.describeLB.text = self.goodsDic[@"CommodityProperty"];
        cell.numLB.text = [NSString stringWithFormat:@"×%@",self.goodsDic[@"CommodityNumber"]];
        cell.selectionStyle = NO;
        return cell;
    } else {
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        if (indexPath.section == 1) {
            // 评分
            [cell.contentView addSubview:self.starsView];
            [self.starsView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.contentView).offset(rateWidth(25));
                make.centerY.equalTo(cell.contentView);
                make.size.mas_offset(CGSizeMake(135, 35));
            }];
            self.starsView.star1.tag = 1;
            self.starsView.star2.tag = 2;
            self.starsView.star3.tag = 3;
            self.starsView.star4.tag = 4;
            self.starsView.star5.tag = 5;
            [self.starsView.star1 addTarget:self action:@selector(pingFenStar:) forControlEvents:(UIControlEventTouchUpInside)];
            [self.starsView.star2 addTarget:self action:@selector(pingFenStar:) forControlEvents:(UIControlEventTouchUpInside)];
            [self.starsView.star3 addTarget:self action:@selector(pingFenStar:) forControlEvents:(UIControlEventTouchUpInside)];
            [self.starsView.star4 addTarget:self action:@selector(pingFenStar:) forControlEvents:(UIControlEventTouchUpInside)];
            [self.starsView.star5 addTarget:self action:@selector(pingFenStar:) forControlEvents:(UIControlEventTouchUpInside)];
            
        } else if (indexPath.section == 2) {
            // 标签
            UITextField *textField = [[UITextField alloc] init];
            textField.font = [UIFont systemFontOfSize:14];
            textField.placeholder = @"请输入标签...";
            [cell.contentView addSubview:textField];
            [textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.contentView).offset(rateWidth(25));
                make.centerY.equalTo(cell.contentView);
                make.size.mas_offset(CGSizeMake(rateWidth(650), rateHeight(60)));
            }];
            textField.delegate = self;
            self.textField = textField;
            if (self.infoDic[@"biaoQian"]) {
                self.textField.text = self.infoDic[@"biaoQian"];
            }
            
        } else if (indexPath.section == 3) {
            // 心得
            UITextView *textView = [[UITextView alloc] init];
            [textView setBackgroundColor:UIColorWhite];
            [cell.contentView addSubview:textView];
            //模仿cell复用
            [textView setPlaceholderWithText:@"商品怎么样？说说体验心得，给其他买家做个参考吧~" Color:[UIColor lightGrayColor]];
            textView.font = [UIFont systemFontOfSize:14];
            textView.delegate = self;
            self.textView = textView;
            [textView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.contentView).offset(rateWidth(25));
                make.right.equalTo(cell.contentView).offset(-rateWidth(25));
                make.top.equalTo(cell.contentView).offset(rateHeight(25));
                make.bottom.equalTo(cell.contentView).offset(-rateHeight(25));
            }];
            if (self.infoDic[@"biaoQian"]) {
                self.textView.text = self.infoDic[@"xinDe"];
            }
            
        } else {
            // 晒一晒
            [cell addSubview:self.collectionView];
            [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset(rateWidth(54));
                make.top.equalTo(cell).offset(rateHeight(37));
                make.right.equalTo(cell).offset(-rateWidth(50));
                make.height.equalTo(@(rateHeight(500)));
            }];
        }
        cell.selectionStyle = NO;
        return cell;
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self.infoDic setObject:_textField.text forKey:@"biaoQian"];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    [self.infoDic setObject:_textView.text forKey:@"xinDe"];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return rateHeight(210);
    } else if (indexPath.section == 1 || indexPath.section == 2) {
        return rateHeight(110);
    } else if (indexPath.section == 3) {
        return rateHeight(240);
    } else {
        return rateHeight(500);
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    } else {
        return rateHeight(70);
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 4) {
        return rateHeight(200);
    } else {
        return 0.01;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return nil;
    } else {
        UIView *bgV = [[UIView alloc] init];
        bgV.backgroundColor = tableViewBgColor;
        NSArray *array = @[@"评分",@"标签",@"心得",@"晒一晒"];
        UILabel *label = [UILabel labelWithText:array[section-1] textColor:UIColorFromRGB(0x323232) fontSize:15];
        [label sizeToFit];
        [bgV addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(rateWidth(25)));
            make.centerY.equalTo(bgV);
        }];
        if (section == 1) {
            UILabel *rightLB = [UILabel labelWithText:@"1-2星差评；3星中评；4-5星好评" textColor:UIColorFromRGB(0x909090) fontSize:13];
            [rightLB sizeToFit];
            [bgV addSubview:rightLB];
            [rightLB mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(bgV).offset(-rateWidth(25));
                make.centerY.equalTo(bgV);
            }];
            
        }
        return bgV;
    }
    
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 4) {
        UIView *bgV = [[UIView alloc] init];
        bgV.backgroundColor = tableViewBgColor;
        
        UIButton *btn = [UIButton buttonWithTitle:@"提交" fontSize:15 titleColor:UIColorWhite background:navBarColor cornerRadius:3];
        [bgV addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(CGSizeMake(rateWidth(600), rateHeight(70)));
            make.center.equalTo(bgV);
        }];
        [btn addTarget:self action:@selector(tiJiaoAction) forControlEvents:(UIControlEventTouchUpInside)];
        
        return bgV;
    } else {
        return nil;
    }
}
#pragma mark - 提交
- (void)tiJiaoAction
{
//    dispatch_group_t group =  dispatch_group_create();
//    dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
//        NSLog(@"队列组：有一个耗时操作完成！");
//    });
//    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
//        NSLog(@"队列组：前面的耗时操作都完成了，回到主线程进行相关操作");
//    });
    
    if (self.selectedPhotos) {
        for (UIImage *img in self.selectedPhotos) {
            [self uploadImg:img];
        }
    } else {
        [self faBu];
    }
}
- (void)faBu
{
    if (self.goodsDic) {
        NSLog(@"filePath-------%@",[self.filePathArray componentsJoinedByString:@"|"]);
        NSString *code = [NSString stringWithFormat:@"%@%@",safeCode,[GetTimestamp getNowTimeTimestamp]];
        [MBProgressHUD showMessage:nil toView:self.view];
        [TFNetworking postWithURLString:[NSString stringWithFormat:@"%@/api/json/member/order.ashx?action=saveordergoodcomment&companyid=%@&code=%@&timestamp=%@",kServerURL,companyId,[MD5Encrypt  MD5ForLower32Bate:code],[GetTimestamp getNowTimeTimestamp]] parameters:@{@"cartid":self.goodsDic[@"CartId"],@"commodityid":self.goodsDic[@"commodityId"],@"commentcontent":self.textView.text,@"commentlevel":self.star,@"commentlabel":self.textField.text,@"commentimages":[self.filePathArray componentsJoinedByString:@"|"]} success:^(id responseObject) {
            [MBProgressHUD hideHUDForView:self.view];
            if (responseObject) {
                [TFHUD addRemindHUD:self.view message:responseObject[@"returnMsg"]];
                if ([responseObject[@"status"] intValue] == 1) {
                    [self.navigationController popViewControllerAnimated:YES];
                    
                }
            }
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
            [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
        }];
    }
}
#pragma mark - 评分
- (void)pingFenStar:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
        if (btn.tag == 1) {
            [_starsView.star2 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            [_starsView.star3 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            [_starsView.star4 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            [_starsView.star5 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            _starsView.star2.selected = YES;
            _starsView.star3.selected = YES;
            _starsView.star4.selected = YES;
            _starsView.star5.selected = YES;
            self.star = @"0";

        } else if (btn.tag == 2) {
            [_starsView.star3 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            [_starsView.star4 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            [_starsView.star5 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            _starsView.star3.selected = YES;
            _starsView.star4.selected = YES;
            _starsView.star5.selected = YES;
            self.star = @"1";

        } else if (btn.tag == 3) {
            [_starsView.star4 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            [_starsView.star5 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            _starsView.star4.selected = YES;
            _starsView.star5.selected = YES;
            self.star = @"2";

        } else if (btn.tag == 4) {
            [_starsView.star5 setImage:UIImageNamed(@"wuxinghui") forState:(UIControlStateNormal)];
            _starsView.star5.selected = YES;
            self.star = @"3";

        } else if (btn.tag == 5) {
            self.star = @"4";
        }
        
    } else {
        [btn setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
        if (btn.tag == 1) {
            _starsView.star1.selected = YES;
            _starsView.star2.selected = YES;
            _starsView.star3.selected = YES;
            _starsView.star4.selected = YES;
            _starsView.star5.selected = YES;
            self.star = @"1";
            
        } else if (btn.tag == 2) {
            [_starsView.star1 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            _starsView.star1.selected = NO;
            self.star = @"2";
            
        } else if (btn.tag == 3) {
            [_starsView.star1 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            [_starsView.star2 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            _starsView.star1.selected = NO;
            _starsView.star2.selected = NO;
            self.star = @"3";
            
        } else if (btn.tag == 4) {
            [_starsView.star1 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            [_starsView.star2 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            [_starsView.star3 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            _starsView.star1.selected = NO;
            _starsView.star2.selected = NO;
            _starsView.star3.selected = NO;
            self.star = @"4";
            
        } else if (btn.tag == 5) {
            [_starsView.star1 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            [_starsView.star2 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            [_starsView.star3 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            [_starsView.star4 setImage:UIImageNamed(@"wuxingjin") forState:(UIControlStateNormal)];
            _starsView.star1.selected = NO;
            _starsView.star2.selected = NO;
            _starsView.star3.selected = NO;
            _starsView.star4.selected = NO;
            self.star = @"5";
        }
    }
}
#pragma mark - 选择图片
- (void)selectImages {
    DPPhotoGroupViewController *controller = [[DPPhotoGroupViewController alloc] init];
    controller.maxSelectionCount = 9;
    controller.delegate = self;
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:controller] animated:YES completion:nil];
}
#pragma mark - DPPhotoGroupViewControllerDelegate
- (void)didSelectPhotos:(NSMutableArray *)photos {
    NSLog(@"%@", photos);
}

#pragma mark - collectionView dataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.selectedPhotos.count + 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TZTestCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:indexPath];
    cell.videoImageView.hidden = YES;
    if (indexPath.row == _selectedPhotos.count) {
        cell.imageView.image = [UIImage imageNamed:@"xiangjishouhou"];
        cell.deleteBtn.hidden = YES;
        cell.gifLable.hidden = YES;
    } else {
        cell.imageView.image = _selectedPhotos[indexPath.row];
        cell.asset = _selectedAssets[indexPath.row];
        cell.deleteBtn.hidden = NO;
    }
    cell.contentView.backgroundColor = kClearColor;
    cell.gifLable.hidden = YES;
    cell.deleteBtn.tag = indexPath.row;
    [cell.deleteBtn addTarget:self action:@selector(deleteBtnClik:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
#pragma mark - Click Event

- (void)deleteBtnClik:(UIButton *)sender {
    [_selectedPhotos removeObjectAtIndex:sender.tag];
    [_selectedAssets removeObjectAtIndex:sender.tag];
    
    [_collectionView performBatchUpdates:^{
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:sender.tag inSection:0];
        [_collectionView deleteItemsAtIndexPaths:@[indexPath]];
    } completion:^(BOOL finished) {
        [_collectionView reloadData];
    }];
}
#pragma mark - collectionView delegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == _selectedPhotos.count) {
        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:3 delegate:self pushPhotoPickerVc:YES];
        // 1.设置目前已经选中的图片数组
        imagePickerVc.selectedAssets = _selectedAssets; // 目前已经选中的图片数组
        [self presentViewController:imagePickerVc animated:YES completion:nil];
    } else
    {
        [_selectedPhotos removeObjectAtIndex:indexPath.row];
        [_selectedAssets removeObjectAtIndex:indexPath.row];
        
        [_collectionView performBatchUpdates:^{
            [_collectionView deleteItemsAtIndexPaths:@[indexPath]];
        } completion:^(BOOL finished) {
            [_collectionView reloadData];
        }];
        //        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:_selectedAssets selectedPhotos:_selectedPhotos index:indexPath.row];
        //        //            imagePickerVc.maxImagesCount = self.maxCountTF.text.integerValue;
        //        //            imagePickerVc.allowPickingOriginalPhoto = self.allowPickingOriginalPhotoSwitch.isOn;
        //        imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
        //        [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        //            _selectedPhotos = [NSMutableArray arrayWithArray:photos];
        //            _selectedAssets = [NSMutableArray arrayWithArray:assets];
        //            _isSelectOriginalPhoto = isSelectOriginalPhoto;
        //            [_collectionView reloadData];
        //            _collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (15 + rateHeight(120)));
        //        }];
        //        [self presentViewController:imagePickerVc animated:YES completion:nil];
    }
}
#pragma mark - TZImagePickerControllerDelegate

/// 用户点击了取消
- (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker {
    // NSLog(@"cancel");
}

// 这个照片选择器会自己dismiss，当选择器dismiss的时候，会执行下面的代理方法
// 如果isSelectOriginalPhoto为YES，表明用户选择了原图
// 你可以通过一个asset获得原图，通过这个方法：[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
// photos数组里的UIImage对象，默认是828像素宽，你可以通过设置photoWidth属性的值来改变它
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
    _selectedPhotos = [NSMutableArray arrayWithArray:photos];
    _selectedAssets = [NSMutableArray arrayWithArray:assets];
    _isSelectOriginalPhoto = isSelectOriginalPhoto;
    [_collectionView reloadData];
    // _collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH));
    
    // 1.打印图片名字
    //    [self printAssetsName:assets];
}

// 如果用户选择了一个视频，下面的handle会被执行
// 如果系统版本大于iOS8，asset是PHAsset类的对象，否则是ALAsset类的对象
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(id)asset {
    _selectedPhotos = [NSMutableArray arrayWithArray:@[coverImage]];
    _selectedAssets = [NSMutableArray arrayWithArray:@[asset]];
    [_collectionView reloadData];
}

// 如果用户选择了一个gif图片，下面的handle会被执行
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(id)asset {
    _selectedPhotos = [NSMutableArray arrayWithArray:@[animatedImage]];
    _selectedAssets = [NSMutableArray arrayWithArray:@[asset]];
    [_collectionView reloadData];
}
#pragma mark - 上传图片
- (void)uploadImg:(UIImage *)image
{
    if (image) {
        [MBProgressHUD showMessage:@"" toView:self.view];
        //1.创建管理者对象
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.responseSerializer = [AFJSONResponseSerializer serializer];
        manager.requestSerializer = [AFJSONRequestSerializer serializer];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html", @"application/javascript", @"text/js",@"application/xml", nil];
        //2.上传文件
        NSString *code = [NSString stringWithFormat:@"%@%@",safeCode,[GetTimestamp getNowTimeTimestamp]];
        [manager POST:[NSString stringWithFormat:@"%@/api/json/upload/upload.ashx?action=memberimages&companyid=%@&code=%@&timestamp=%@",kServerURL,companyId,[MD5Encrypt  MD5ForLower32Bate:code],[GetTimestamp getNowTimeTimestamp]] parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            [MBProgressHUD hideHUDForView:self.view];
            //上传文件参数
            if (image) {
                // 产品图片
                NSData *pictureData = UIImageJPEGRepresentation(image, 0.5);
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                formatter.dateFormat = @"yyMMddHHmmss";
                NSString *fileName = [formatter stringFromDate:[NSDate date]];
                NSString *nameStr = @"filePath"; // 参数名(一定不能写错)
                [formData appendPartWithFileData:pictureData name:nameStr fileName:[NSString stringWithFormat:@"image%@.jpg", fileName] mimeType:@"image/jpeg"];
            }
            
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            //打印上传进度
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            //请求成功
            NSLog(@"-----%@", responseObject);
            [self.filePathArray addObject:responseObject[@"data"]];
            if (self.filePathArray.count == self.selectedPhotos.count) {
                [self faBu];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            //请求失败
            [TFHUD addRemindHUD:self.view message:@"保存失败"];
            NSLog(@"%@",error);
        }];
    }
}
- (MyStarView *)starsView
{
    if (!_starsView) {
        _starsView = [[MyStarView alloc] initWithFrame:CGRectMake(0, 0, 135, 35)];
    }
    return _starsView;
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(rateWidth(120), rateWidth(120));
        flowLayout.minimumInteritemSpacing = 15;
        flowLayout.minimumLineSpacing = 15;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, rateWidth(40), rateHeight(200)) collectionViewLayout:flowLayout];
        _collectionView.alwaysBounceVertical = YES;
        _collectionView.backgroundColor = kClearColor;
        _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        [_collectionView registerClass:[TZTestCell class] forCellWithReuseIdentifier:@"TZTestCell"];
    }
    return _collectionView;
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, kScreenWidth, kScreenHeight-SafeAreaTopHeight-SafeAreaBottomHeight) style:(UITableViewStyleGrouped)];
        _tableView.backgroundColor = UIColorFromRGB(0xf5f5f5);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = NO;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
    }
    return _tableView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
